package ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.contacto;

import model.Aplicacion.Agenda;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import simulaPersistencia.CiudadHome;
import ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.HomePage;
import ar.edu.unq.tpi.labso.rochi.agendaRochi.Wicket.apliccion.ContactoDatProvider;
import clasesPrincipales.Ciudad;
import clasesPrincipales.Contacto;

public class EditarContactoPage extends WebPage {
	private static final long serialVersionUID = 1L;

	final ContactoDatProvider provider ;
	public EditarContactoPage( ContactoDatProvider provider) {
		
		super(new CompoundPropertyModel<Contacto>(
				provider.getSeleccionado()));
		this.provider= provider;
		Form<Contacto> form = new Form<Contacto>("contactoEditForm");	
		this.add(form);

		
		  form.add(new Label("lbl_nombre","Nombre"));
		  form.add(new TextField<String>("nombre"));
		  form.add(new Label("lbl_telefono","Telefono"));
		  form.add(new TextField<String>("telefono"));//textBox
		  form.add(new Label("lbl_mail","Mail"));
		  form.add(new TextField<String>("mail"));
		  form.add(new Label("lbl_ciudad","Ciudad"));
		  form.add(new DropDownChoice("ciudad", ((CiudadHome)Agenda.getHome(Ciudad.class)).buscarTodos()));//combo
		  form.add(new SubmitLink("botonEditarContacto"){
		
			private static final long serialVersionUID = 1L;

			@Override
			public void onSubmit() {
				  EditarContactoPage.this.provider.editar((Contacto)EditarContactoPage.this.getDefaultModelObject());
				this.setResponsePage(new HomePage());
			};
		  });

		  form.add(new Link("botonVolverHome"){
				private static final long serialVersionUID = 1L;
				public void onClick() {
					EditarContactoPage.this.setResponsePage(new HomePage());
				}});
				
		};
	}
	

